﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Fis.Win.Utils;

namespace Fis.Win.Forms
{
    public partial class LoginForm : BaseForm
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        public override void InitializeBinding()
        {
            edBookID.Text = AppSession.BookID;
            edName.Text = AppSession.UserName;
            edPwd.Text = string.Empty;
        }

        private void bnCancel_Click(object sender, EventArgs e)
        {
            ViewResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }

        private void bnOK_Click(object sender, EventArgs e)
        {
            if (!dxValidationProvider1.Validate())
            {
                return;
            }

            var param = new System.Collections.Hashtable();
            param["SBOOKID"] = edBookID.EditValue.ToString().Trim();
            param["FUSERNAME"] = edName.EditValue.ToString().Trim();
            param["FPASSWORD"] = Agile.Engine.Utils.StringUtils.ToMD5(edPwd.EditValue.ToString());
            if (ViewProvider.ExecuteValidate(param))
            {
                ViewResult = System.Windows.Forms.DialogResult.OK;
                Fis.Win.Utils.CacheContext.ClearCache();

                if (Fis.Win.Utils.AppSession.IsAdminUser)
                {
                    //没有帐套
                    if (param.ContainsKey("nobook"))
                    {
                        var v = UIManager.ShowEdit<BookInfoForm>("BookInfoProvider");
                        ViewResult = v.ViewResult;
                    }
                }
            }


            if ((DialogResult)ViewResult == System.Windows.Forms.DialogResult.OK)
            {
                Fis.Win.Utils.AppSession.InitializeBookInfo();
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(Message);
            }
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {

        }
    }
}
